﻿namespace Audit.EntityFramework.Core.Samples.Extensions;

public static class AuditEntityFrameworkCoreExtensions
{
    /// <summary>
    /// 从自定义字段中获取用户ID。
    /// </summary>
    /// <param name="customFields">自定义字段字典。</param>
    /// <returns>用户ID，如果不存在则返回null。</returns>
    public static int? GetUserIdFromCustomFields(this Dictionary<string, object> customFields)
    {
        if (customFields.TryGetValue("UserId", out var value) && value is int userId)
        {
            return userId;
        }
        return null;
    }
}
